<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>20.有效的括号</title>
</head>

<body>

</body>
<script>
    /**
     * @param {string} s
     * @return {boolean}
     */
    var isValid = function (s) {
        let arr = [];
        let sArr = s.split("");

        for (let i = 0; i < sArr.length; i++) {
            switch (sArr[i]) {
                case '(':
                    arr.push(')');
                    break;
                case '[':
                    arr.push(']');
                    break;
                case '{':
                    arr.push('}');
                    break;
                default:
                    if (arr.pop() != sArr[i]) {
                        return false;
                    }
            }
        }
        if (arr.length == 0) {
            return true;
        }else{
            return false;
        }
    };
    console.log(isValid("("));
</script>

</html>